package org.tp8.sampleapp.util;

import java.lang.reflect.ParameterizedType;

/**
 * The Class GenericsUtil.
 */
public class GenericsUtil {

	/**
	 * The Constant log.
	 */
	private final static SampleAppLogger log = new SampleAppLogger(
			GenericsUtil.class);

	/**
	 * Figure out persistent class.
	 * 
	 * @param <C>
	 *            the generic type
	 * @param object
	 *            the object
	 * @return the class
	 */
	@SuppressWarnings("unchecked")
	public static <C> Class<C> figureOutPersistentClass(final C object) {
		final Class<C> clazz = (Class<C>) ((ParameterizedType) (object
				.getClass().getGenericSuperclass())).getActualTypeArguments()[0];
		log.debug("persistentClass set to: " + clazz.getName());
		return clazz;
	}
}
